package com.itany.controller;


import com.github.pagehelper.PageInfo;
import com.itany.ApplicationContextHolder;
import com.itany.intercepter.PermissionInterceptor;
import com.itany.pojo.User;
import com.itany.service.ITestService;
import com.itany.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.awt.font.MultipleMaster;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    ITestService testService;

    @RequestMapping("/findAll")
    @ResponseBody
    public Map<String, Object> findAll(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer rows) {
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo<User> info = testService.findUserAll(page, rows);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }


    @RequestMapping("/error")
    public void error() throws Exception {
        throw new Exception("测试全局异常");
    }


    @RequestMapping("/allowedUrls")
    @ResponseBody
    public ActionResult allowedUrls() {
        ActionResult result = new ActionResult();

        PermissionInterceptor bean = ApplicationContextHolder.getBean(PermissionInterceptor.class);
        result.setData(bean);
        return result;
    }


}
